package com.lxy.myweather;

import com.lxy.data_bean.PM2_5_bean;
import com.lxy.data_bean.RealTime_Weather_bean;
import com.lxy.data_bean.SixDayWeather_bean;
import com.lxy.thread.AllThread;
import com.lxy.util.List_Adapter;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.view.Menu;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

public class MainActivity extends Activity {
	private LinearLayout bg;
	private TextView city; //
	private TextView weatherContion; //
	private TextView pm25; //
	private TextView sd; //
	private TextView realTemperature; //
	private TextView today_date; //
	private ImageView today_img; //
	private TextView today_tem;  //
	//------------------------
	private TextView date_1; //
	private ImageView img_1; //
	private TextView tem_1;  //
	//------------------------
	private TextView date_2; //
	private ImageView img_2; //
	private TextView tem_2;  //
	//------------------------
	private TextView date_3; //
	private ImageView img_3; //
	private TextView tem_3;  //
	//------------------------
	private TextView date_4; //
	private ImageView img_4; //
	private TextView tem_4;  //
	//------------------------
	private TextView date_5; //
	private ImageView img_5; //
	private TextView tem_5;  //
	//---listview----
	private ListView index_list;
	private TextView bottom_left;
	private TextView bottom_centre;
	private TextView bottom_right;
	private AllThread allThread;
	//
	public Handler h=new Handler(){
		@Override
		public void handleMessage(Message msg) {
			switch(msg.what){
			case 1:{
				deal_RealTime_Weather((RealTime_Weather_bean)msg.obj);
			}break;
			case 2:{
				deal_PM2_5((PM2_5_bean)msg.obj);
			}break;
			case 3:{
				deal_SixDay_Weather((SixDayWeather_bean)msg.obj);
			}break;
			}
		}
	};
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		init();
		index_list.setAdapter(new List_Adapter(this));
		allThread=new  AllThread(h, this, "太原");
		allThread.start();
		
		
	}
	
	private void init(){
		bg=(LinearLayout) findViewById(R.id.backGroud);
		city=(TextView) findViewById(R.id.L1_t_title_city);
		weatherContion=(TextView) findViewById(R.id.L2_t_weather_condition); //
		pm25=(TextView) findViewById(R.id.L3_1_pm25_sd_t_pm25);
		sd=(TextView) findViewById(R.id.L3_1_pm25_sd_t_sd);
		realTemperature=(TextView) findViewById(R.id.L3_2_Real_time_temperature_t_tem); //
		today_date=(TextView) findViewById(R.id.L3_3_Date_t_date); //
		today_img=(ImageView) findViewById(R.id.L3_3_Date_image_v); //
		today_tem=(TextView) findViewById(R.id.L3_3_Date_t_today_tem);  //
		//------------------------
		date_1=(TextView) findViewById(R.id.L4_SixDay_t_1date); //
		img_1=(ImageView) findViewById(R.id.L4_SixDay_image_1v); //
		tem_1=(TextView) findViewById(R.id.L4_SixDay_t_1tem);  //
		//------------------------
		date_2=(TextView) findViewById(R.id.L4_SixDay_t_2date); //
		img_2=(ImageView) findViewById(R.id.L4_SixDay_image_2v); //
		tem_2=(TextView) findViewById(R.id.L4_SixDay_t_2tem);  //
		//------------------------
		date_3=(TextView) findViewById(R.id.L4_SixDay_t_3date); //
		img_3=(ImageView) findViewById(R.id.L4_SixDay_image_3v); //
		tem_3=(TextView) findViewById(R.id.L4_SixDay_t_3tem);  //
		//------------------------
		date_4=(TextView) findViewById(R.id.L4_SixDay_t_4date); //
		img_4=(ImageView) findViewById(R.id.L4_SixDay_image_4v); //
		tem_4=(TextView) findViewById(R.id.L4_SixDay_t_4tem);  //
		//------------------------
		date_5=(TextView) findViewById(R.id.L4_SixDay_t_5date); //
		img_5=(ImageView) findViewById(R.id.L4_SixDay_image_5v); //
		tem_5=(TextView) findViewById(R.id.L4_SixDay_t_5tem);  //
		//---listview----
		index_list=(ListView) findViewById(R.id.L5_index_listview);
		bottom_left=(TextView) findViewById(R.id.L6_bottom_left_t1);
		bottom_centre=(TextView) findViewById(R.id.L6_bottom_centre_t2);
		bottom_right=(TextView) findViewById(R.id.L6_bottom_right_t3);
	}
	
	private void deal_RealTime_Weather(RealTime_Weather_bean bean){
		realTemperature.setText(bean.getTempretrue()+"℃");
		sd.setText("湿 度："+bean.getSd());
	}
	private void deal_SixDay_Weather(SixDayWeather_bean bean){
		city.setText(bean.getCity());
		weatherContion.setText(bean.getWeather_describe());
//		bg.setBackgroundResource(bean.getBgpic_id());
		today_date.setText(bean.getEveryDay()[0].getDate());
		today_img.setImageResource(bean.getEveryDay()[0].getImg_id());
		today_tem.setText(bean.getEveryDay()[0].getTemps());
		
		date_1.setText(bean.getEveryDay()[1].getDate());
		img_1.setImageResource(bean.getEveryDay()[1].getImg_id());
		tem_1.setText(bean.getEveryDay()[1].getTemps());
		
		date_2.setText(bean.getEveryDay()[2].getDate());
		img_2.setImageResource(bean.getEveryDay()[2].getImg_id());
		tem_2.setText(bean.getEveryDay()[2].getTemps());
		
		date_3.setText(bean.getEveryDay()[3].getDate());
		img_3.setImageResource(bean.getEveryDay()[3].getImg_id());
		tem_3.setText(bean.getEveryDay()[3].getTemps());
		
		date_4.setText(bean.getEveryDay()[4].getDate());
		img_4.setImageResource(bean.getEveryDay()[4].getImg_id());
		tem_4.setText(bean.getEveryDay()[4].getTemps());
		
		date_5.setText(bean.getEveryDay()[5].getDate());
		img_5.setImageResource(bean.getEveryDay()[5].getImg_id());
		tem_5.setText(bean.getEveryDay()[5].getTemps());
		
		index_list.setAdapter(new List_Adapter(bean.IndexList(), this));
		
	}
	private void deal_PM2_5(PM2_5_bean bean){
		pm25.setText("PM2.5："+bean.getPm2_5());
	}
	
	
	@Override
	public void finish() {
		allThread.interrupt();
		super.finish();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
